package com.Controller;
import com.Service.LoginService;
import com.Service.RegistService;
import com.Service.SmsService;
import com.common.Result;
import com.pojo.PwdResetDTO;
import com.pojo.RegisterDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * 登录、无密码登录、注册、密码重置等接口层
 */
@Controller
@RequestMapping("/loginC")
public class LoginController {
    @Autowired
    private LoginService loginService;
    @Autowired
    private RegistService registService;
    @PostMapping("/login")
    public Result login(@RequestParam String username, @RequestParam String password,
                        HttpServletRequest req, HttpServletResponse resp) throws IOException {
        return loginService.login(username, password, req, resp);
    }
    @PostMapping("/noPwdLogin")
    @ResponseBody
    public Result noPwdLogin(@RequestParam String username, @RequestParam String confirmCode,
                             HttpServletRequest req, HttpServletResponse resp) {
        return loginService.noPwdLogin(username, confirmCode, req, resp);
    }
    @PostMapping("/register")
    @ResponseBody
    public Result register(@RequestBody RegisterDTO registerDTO) {//直接将前端传过来的json字符串放入registerDTO
        return registService.register(registerDTO);
    }
    @PostMapping("/passwordReset")
    @ResponseBody
    public Result passwordReset(@RequestBody PwdResetDTO resetDTO) {
        return loginService.passwordReset(resetDTO);
    }

}
